<template>
    <div class="card">
        <el-card>
           
            <el-form :model="user" label-width="100px" style="padding-right: 50px">
                <div style="margin: 15px; text-align: center">
                    <el-upload class="avatar-uploader" action="/files/upload" :show-file-list="false"
                        :on-success="handleAvatarSuccess">
                        <img v-if="user.icon" :src="user.icon" class="avatar" />
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </div>
                <el-form-item label="账号" prop="username">
                    <el-input v-model="user.phone" disabled placeholder="账号"></el-input>
                </el-form-item>

                <el-form-item label="昵称" prop="nickName">
                    <el-input v-model="user.nickName" placeholder="昵称"></el-input>
                </el-form-item>
                <div style="text-align: center; margin-bottom: 20px">
                    <el-button type="primary" @click="update">保 存</el-button>
                </div>
            </el-form>
        </el-card>
    </div>
</template>
<script>
import service from "@/request"
export default {
    data() {
        return {
            user: {},
            num: 0,
        }
    },
    mounted() {
        this.getinfo()
      
    },
    methods: {
     
   
        async update() {
            const res = await service.post("/account/updateinfo", this.user);
            console.log(res)
            this.getinfo()
        },
        handleAvatarSuccess(e) {
            this.user.icon = e.data
        },
        async getinfo() {
            const res = await service.get("/account/info");
            console.log(res)
            this.user = res.data

            console.log()
            window.localStorage.setItem("userinfo", JSON.stringify(this.user))

        },
    }
}

</script>
<style>
.card {
    width: 100%;
    height: auto;
    padding: 10px;
    box-sizing: border-box;
}
</style>
<style scoped>
/deep/.el-form-item__label {
    font-weight: bold;
}

/deep/.el-upload {
    border-radius: 50%;
}

/deep/.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border-radius: 50%;
}

/deep/.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px !important;
    text-align: center;
    border-radius: 50%;
}

.avatar {
    width: 120px;
    height: 120px;
    display: block;
    border-radius: 50%;
}
</style>